When the syntax new Guid()
(i.e. parameterless instantiation) is used, it must be that one of three things is wanted:
- An empty GUID, in which case
Guid.Empty
is clearer.
- A randomly-generated GUID, in which case
Guid.NewGuid()
should be used.
- A new GUID with a specific initialization, in which case the initialization parameter is missing.
This rule raises an issue when a parameterless instantiation of the Guid
struct is found.
Noncompliant code example
Public Sub Foo()
Dim G1 As New Guid ' Noncompliant - what's the intent?
Dim G2 As Guid = Nothing ' Noncompliant
End Sub
Compliant solution
public void Foo(byte[] bytes)
Public Sub Foo(Bytes As Byte())
Dim G1 As Guid = Guid.Empty
Dim G2 As Guid = Guid.NewGuid()
Dim G3 As Guid = New Guid(Bytes)
End Sub